﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.Unity;
using ePlanet.ResourceRequest.Services;
using ePlanet.ResourceRequest.DataAccess;
using System.Data;
using Wuqi.Webdiyer;

namespace Web.Views.TempUserManage
{
    public partial class TempUserManager : PageBase
    {
        [Dependency]
        public ITempUserService m_ITempUserService
        {
            get;
            set;
        }

        private Web.SystemLogin.Models.User m_CurrentUser
        {
            get
            {
                return (Web.SystemLogin.Models.User)Session["CurrentUser"];
            }
        }

        private TempUserStausEnum m_TempUserStausEnum
        {
            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["StatusID"]))
                {
                    return (TempUserStausEnum)Enum.Parse(typeof(TempUserStausEnum), Request.QueryString["StatusID"]);
                }
                else
                {
                    return TempUserStausEnum.Originale;
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    this.BindData();
                }
            }
            catch (Exception ex)
            {
                Alert(ex.Message);
            }
        }

        #region 私有方法
        private void BindData()
        {
            int recordCount = 0;
            DataTable tempUesrDt = this.m_ITempUserService.GetTempUserList(this.m_TempUserStausEnum, this.m_CurrentUser.User_ID);
            this.gv_TempUser.DataSource = PageDataList.GetPagedTable(tempUesrDt, this.pager.CurrentPageIndex, this.pager.PageSize, out recordCount);
            this.pager.RecordCount = recordCount;
            this.gv_TempUser.DataBind();
        }

        protected void gv_TempUser_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRow row = ((DataRowView)e.Row.DataItem).Row;
                e.Row.Cells[1].Text = string.Format("<a  href='TempUserView.aspx?TempUserID={0}&StatusID={1}'>{2}</a>",
                    row["TempUserID"],Request.QueryString["StatusID"], row["UserName"]);
            }
        }

        /// <summary>
        /// 分页数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void pagerdo_PageChanging(object sender, PageChangingEventArgs e)
        {
            pager.CurrentPageIndex = e.NewPageIndex;
            BindData();
        }
        #endregion
    }
}